import { useRef } from 'react';
import { Button, Modal, Space } from 'antd';
// import ModalProV1, { type IModalRef } from '@/components/ModalProV1';
import type { IRes } from '@/utils/request';

const selectTestForm = (data: { title: string }, type: string) =>
	new Promise<IRes<{ title: string }>>((resolve, reject) => {
		if (data.title === '123') {
			setTimeout(() => {
				resolve({ code: 200, data: { title: '牛逼，成功了' }, message: 'success' });
			}, 2000);
		} else {
			reject({ code: 500, data: { title: '垃圾，传错了' }, message: 'error' });
		}
	});

const HookModalView = () => {
	// const modalRef = useRef<IModalRef>();

	const handleSubmit = () => {
		return selectTestForm({ title: '123' }, '123')
			.then((res) => {
				console.log(res.data);
			})
			.finally(() => {
				console.log('略略略');
			});
	};

	return (
		<>
			<Space>
				{/* <Button type="primary" onClick={() => modalRef.current.setModal(true)}>
					打开弹窗
				</Button> */}
				<Button
					type="primary"
					ghost
					onClick={() => {
						Modal.confirm({
							title: '确认提交？',
							onOk: async () => {
								await selectTestForm({ title: '123' }, '123');
							}
						});
					}}
				>
					提示弹窗
				</Button>
			</Space>
			{/* <ModalProV1 ref={modalRef} onOk={handleSubmit} /> */}
		</>
	);
};

export default HookModalView;
